package com.xiongwei.iterator;

import java.util.Iterator;

/**
 * @author XiongWei
 * @date 2024/2/20
 */
public class ComputerCollegeIterator implements Iterator {

    Department[] departments;
    int position = 0;

    public ComputerCollegeIterator(Department[] departments) {
        this.departments = departments;
    }

    @Override
    public boolean hasNext() {
        if (position < departments.length && departments[position] != null) {
            return true;
        }
        return false;
    }

    @Override
    public Object next() {
        if (hasNext()) {
            return departments[position++];
        }
        return null;
    }
}
